package RootDNSServer;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author: 0162977
 * @Date: 2020/12/3 15:40
 */
public class ManageThread implements Runnable {

    DatagramSocket socket = null;

    public ManageThread(DatagramSocket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {

        System.out.println("维护线程开启");
        while(true){
            try {
                InetAddress address = null;
                DatagramPacket packet = null;

                address = InetAddress.getByName("localhost");

                byte[] data2 = ("d,"+ RootDNSServer.ShareSpaceAndFun.myPort+",100").getBytes();
                packet = new DatagramPacket(data2, data2.length, address, 4060);
                socket.send(packet);

            } catch (IOException e) {
                e.printStackTrace();
            }


            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}